Skip to content

Fix: Handle invalid dates in serialization - #3554

Closed
trentonallan wants to merge 8 commits into
brianc:masterfrom
trentonallan:fix-invalid-date-3318
Closed

trentonallan wants to merge 8 commits into
brianc:masterfrom
trentonallan:fix-invalid-date-3318

Conversation

@trentonallan

Copy link
Copy Markdown

Fixes #3318

Problem

new Date(undefined) and other invalid dates were being serialized as "0NaN-NaN-NaNTNaN:NaN:NaN.NaN+NaN:NaN" instead of being handled properly.

Solution

Added validation in dateToString and dateToStringUTC functions to check if date is valid before serialization using isNaN(date.getTime()). Invalid dates now throw a TypeError with a clear error message.

Testing

  • Added unit tests to verify invalid dates throw errors
  • Added test to ensure valid dates still work correctly
  • All existing tests pass

@charmander

charmander commented Oct 6, 2025

Copy link
Copy Markdown
Collaborator

waste of maintainer time with incorrect AI-generated pull request, exhibit n

A correct implementation is already available in #3330.

@charmander charmander closed this Oct 6, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Do not serialize new Date(undefined) as "0NaN-NaN-NaNTNaN:NaN:NaN.NaN+NaN:NaN"

2 participants